'use strict';

module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/pages/pub/page_index 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		const db = uniCloud.database();




		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			_
		} = util;
		let {
			uid,
			user_id,
			appid,
			todatStart,
			erindex_cate
		} = data;
		let res = {
			code: 0,
			msg: "",
			videoList: [],
			dataList: [],
			swiperList: []
		};
		var nowtime = new Date().getTime()
		// 业务逻辑开始-----------------------------------------------------------

		//====加载首页推荐视频====
		let videoList = await db.collection('a_tv').where({
			status: true,
			appid: _.or(_.eq([]), _.in([appid])) //数组为空或包含了appid,既满足条件
		}).orderBy('sort', 'asc').limit(6).get()
		res.videoList = videoList.data
		//====加载首页推荐视频结束====
		//====抖音客服配置====
		const dypz = await db.collection('a_appid').where({
			appid: appid //数组为空或包含了appid,既满足条件
		}).get()
		res.dykefu = dypz.data[0]
		//====抖音客服配置结束====
		//====获取推荐的视频数据====
		const dbinfo = await db.collection('a_tv_series').where({
			appid: _.or(_.eq([]), _.in([appid])), //数组为空或包含了appid,既满足条件
			is_recommend: true
		}).orderBy('like_num', 'desc').get();
		let dataList = dbinfo.data;
		for (var i = 0; i < dataList.length; i++) {
			dataList[i].like = false;

		}
		res.dataList = dataList
		//====获取推荐的视频数据结束====

		//====获取首页轮播图信息====
		const swiperList = await db.collection('b_swiper').where({
			appid: _.or(_.eq([]), _.in([appid])) //数组为空或包含了appid,既满足条件
		}).orderBy('sort', 'asc').get()
		res.swiperList = swiperList.data
		//====获取首页轮播图信息结束====

		//====获取首页优惠弹窗图====
		const index_pic = await db.collection('a_config').where({
			name: "youhui"
		}).get()
		res.indexpic = index_pic.data[0].indexpic || ""
		//====获取首页优惠弹窗图====

		//====获取个人中心导航图标====
		const ucenter_icons = await db.collection('b_navbar').where({
			appid: _.or(_.eq([]), _.in([appid])), //数组为空或包含了appid,既满足条件
			type: "ucenter",
			status: 1
		}).orderBy('sort', 'asc').get()
		res.ucenter_icons = ucenter_icons.data
		//====获取个人中心导航图标====

		//====获取首页导航图标====
		const index_icons = await db.collection('b_navbar').where({
			appid: _.or(_.eq([]), _.in([appid])), //数组为空或包含了appid,既满足条件
			type: "index",
			status: 1
		}).orderBy('sort', 'asc').get()
		res.index_icons = index_icons.data
		//====获取首页导航图标====

		//====首页弹窗活动(每次进入都弹)====
		const active = await db.collection('a_config').where({
			name: "index_activity"
		}).get();
		res.active = active.data[0]
		//====首页弹窗活动(每次进入都弹)====

		//====新人首充配置信息====
		const xrsc = await db.collection('a_config').where({
			name: "youhui"
		}).get();
		res.xrsc = xrsc.data[0]
		//====新人首充配置信息====

		//加载二级页面全部视频
		let ervideoList = await db.collection('a_tv').where({
			status: true,
			appid: _.or(_.eq([]), _.in([appid])) //数组为空或包含了appid,既满足条件
		}).orderBy('sort', 'asc').get()
		res.ervideoList = ervideoList.data

		//====加载二级页面类型视频====
		let flList = await db.collection('a_tv').where({
			status: true,
			erindex_cate,
			appid: _.or(_.eq([]), _.in([appid])) //数组为空或包含了appid,既满足条件
		}).orderBy('sort', 'asc').get()
		res.flList = flList.data
		// 业务逻辑结束-----------------------------------------------------------
		return res;

	}
}